package fiarproject;

/**
 *
 * @author Luke Richardson
 * @author Pok Ng
 */
public class Board {
    private int boardWidth;
    private final int fullBoard;
    private final int maxEmpty;
    private int [][] board;

    /***
     * Constructor allows a board to be created, already populated with pieces.
     * 
     * @param board Pre-occupied fiar board
     */
    public Board(int[][] board) {
        this(board.length);
        this.board = board;
    }

    /**
     * Constructor to create empty game board
     * @param boardWidth Size that board should be initialised to
     */
    public Board(int boardWidth) {
        this.boardWidth = boardWidth;
        fullBoard = boardWidth * boardWidth % 2 == 0 ? boardWidth * boardWidth : boardWidth * boardWidth - 1;
        maxEmpty = boardWidth * boardWidth - fullBoard;
    }

    /***
     * Check the number of occupied positions on the board is equal to FULL_BOARD 
     * @return true if game is complete
     */
    public boolean isBoardFull() {
        int emptyPositions = 0;

        for(int[] row: board) {
            for(int i: row) {
                if(i==FiarGame.EMPTY) emptyPositions++;
            }
        }
        return emptyPositions==maxEmpty;
    }

    public int getPosition(int w, int h) {
        return board[w][h];
    }

    public int getBoardWidth() {
        return boardWidth;
    }
}
